package com.zsc.shixun.controller;

import com.zsc.shixun.common.CommonResult;
import com.zsc.shixun.common.ResultUtil;
import com.zsc.shixun.service.function.MyFollowedService;
import com.zsc.shixun.utils.LoginMessageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 我的粉丝
 * </p>
 *
 * @author ZWYZY
 * @since 2020/6/7
 */
@Controller
@RequestMapping("/followed")
public class FollowedController {
    private static final Logger logger = LoggerFactory.getLogger(FollowedController.class);

    @Autowired
    private MyFollowedService myFollowedService;
    @Autowired
    private LoginMessageUtils loginMessageUtils;

    @RequestMapping("/index")
    public String index(HttpServletRequest request) {
        request.setAttribute("followListVO", myFollowedService.list(loginMessageUtils.getMessage().loginUser.getId()));
        return "admin/followed/index";
    }

    /**
     * 获取粉丝列表
     *
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    @Secured(value = "ROLE_followed_select")
    public CommonResult getData() {
        return ResultUtil.success(myFollowedService.list(loginMessageUtils.getMessage().loginUser.getId()));
    }

    /**
     * 删除粉丝
     *
     * @param id
     * @return
     */
    @GetMapping("/delete")
    @ResponseBody
    @Secured(value = "ROLE_followed_delete")
    public CommonResult delete(@NotNull(message = "id不能为空") @RequestParam(required = false) Long id) {
        myFollowedService.delete(id, loginMessageUtils.getMessage().loginUser.getId());
        return ResultUtil.success("取消被关注成功哦，亲");
    }
}
